package com.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @ClassName: SocketClientOne
 * @Description:
 * @Date 2024/04/25 16:23
 * @Author songshaoqiu
 **/
public class SocketClientOne {
    public static void main(String[] args) throws IOException {
        //连接服务器
        Socket socket = new Socket("localhost", 9001);
        //发送数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello bio from client A".getBytes());
        outputStream.flush();

        //接收服务端返回的数据
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int read = inputStream.read(bytes);
        System.out.println("接收 服务器返回的数据"+new String(bytes,0,read));
        socket.close();
    }
}
